package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import main.Controller;

import backend.ZauberVariante;

/**
 * @author Christian
 * @since 0.15d
 */
public class AddZauberVarianteController implements ActionListener {
	
	/**
	 * 
	 */
	private AddZauberVariante panel = null;
	
	/**
	 * 
	 * @param panel AddPanel
	 */
	public AddZauberVarianteController(AddZauberVariante panel) {

		this.panel = panel;
	}
	
	/**
	 * @param e Event
	 */
	@Override
	public void actionPerformed(ActionEvent e) {

		if (e.getSource() instanceof JButton) {
			JButton button = (JButton) e.getSource();
			if (button.getText().equals("speichern")) {
				ZauberVariante newVariante = new ZauberVariante();
				newVariante.setAnmerkung(panel.getJAnmerkungTextArea().getText());
				newVariante.setKommentar(panel.getJKommentarTextArea().getText());
				newVariante.setKosten(panel.getJKostenTextArea().getText());
				newVariante.setName(panel.getJVariantenNameTextArea().getText());
				newVariante.setWirkungsDauer(panel.getJWirkungsDauerTextArea().getText());
				newVariante.setZauberDauer(panel.getJZauberDauerTextArea().getText());
				newVariante.setZauberName((String) panel.getJZauberNameComboBox()
						.getSelectedItem());
				newVariante.setRepaesentation((String) panel.getJRepComboBox().getSelectedItem());
				newVariante.setReichweite(panel.getJReichweiteTextArea().getText());
				Controller.getDatenController().addZauberVariante(newVariante);
				Controller.getGuiController().zeigeHauptfenster();
			}
		}
	}
}
